package com.study.java.service.impl;

import com.study.java.dao.UserDao;
import com.study.java.dao.impl.UserDaoImpl;
import com.study.java.domain.User;
import com.study.java.service.UserService;

/**
* @Name: UserServiceImpl
* @Description: 用户信息操作Service接口实现类
* @Author: XXX
* @CreateDate: XXX
* @Version: V1.0
 */
public class UserServiceImpl implements UserService {
	
	private UserDao userDao = new UserDaoImpl() ;

	public User login(String username, String password) {
		User user = null ;
		try {
			user = userDao.getUserByUsernameAndPassword(username, password) ;
		} catch (Exception e) {
			e.printStackTrace() ;
		}
		return user;
	}

	public boolean register(User user) {
		//判断用户名是否已经存在
		User u = userDao.getUserByUsername(user.getUsername()) ;
		if(u == null) {
			userDao.addUser(user) ;
			return true ;
		}
		return false;
	}

}
